﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// scriptClass 的摘要说明
/// </summary>
public class ScriptClass : System.Web.UI.Page
{
    public ScriptClass()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    public class ResponseData
    {
        /// <summary>
        /// 1：代表请求正常
        /// </summary>
        public int code { get; set; }
        public string message { get; set; }
        public object data { get; set; }
    }
    public class MethodRes
    {
        public int code { get; set; }
        public string message { get; set; }
        public object data { get; set; }
    }
    public void Json(object data)
    {
        string json = JSON.Encode(data);
        Response.Write(json);
    }
    /// <summary>
    /// 常用时间格式
    /// </summary>
    /// <returns></returns>
    public string GetDateTimeString()
    {
        return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
    }
    /// <summary>
    /// 短时间格式
    /// </summary>
    /// <returns></returns>
    public string GetDateTimeStringShort()
    {
        return DateTime.Now.ToString("yyyyMMddHHmmss");
    }
    /// <summary>
    /// 检测账号合法
    /// </summary>
    /// <param name="num"></param>
    /// <returns></returns>
    public MethodRes TestNum(Hashtable h_user)
    {
        MethodRes mr = new MethodRes();
        try
        {
            if (h_user.Count == 0)
            {
                mr.code = -1;
                mr.message = "账号不存在";
                return mr;
            }
            if (h_user["isDisable"].ToString() == "1")
            {
                mr.code = -1;
                mr.message = "账号已禁用";
                return mr;
            }
            DateTime dt_time = Convert.ToDateTime(GetDateTimeString());
            if (Convert.ToDateTime(h_user["expireTime"]) < dt_time)//到期时间小于当前时间  已过期
            {
                mr.code = -1;
                mr.message = "账号已到期，请联系管理员";
                return mr;
            }
            mr.code = 0;
            mr.message = "ok";
        }
        catch (Exception ex)
        {
            mr.code = -1;
            mr.message = "出错了,错误详情=> " + ex.Message;
            return mr;
        }
        return mr;
    }
}